package com.anjiplus.template.gaea.business.work.point.controller;

import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.curd.controller.BaseResponse;
import com.anjiplus.template.gaea.business.work.point.entity.Point;
import com.anjiplus.template.gaea.business.work.point.service.PointService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 参数点controller
 *
 * @author yxm
 */
@RestController
@RequestMapping("/point")
public class PointController extends BaseResponse {

    private PointService pointService;

    public PointController(PointService pointService) {
        this.pointService = pointService;
    }

    /**
     * 查询全部参数点列表
     *
     * @return
     */
    @GetMapping("/listAll")
    public ResponseBean listAll() {
        return responseSuccessWithData(pointService.listAll());
    }

    /**
     * 查询指定站点和参数点名称的参数点列表
     *
     * @param id   站点id
     * @param name 参数点name
     * @return
     */
    @GetMapping("/listByStationIdAndPointName/{id}/{name}")
    public ResponseBean listByStationIdAndPointName(@PathVariable String id, @PathVariable String name) {
        return responseSuccessWithData(pointService.listByStationIdAndPointName(id, name));
    }

    /**
     * 查询指定站点的参数点列表
     *
     * @param id 站点id
     * @return
     */
    @GetMapping("/listByStationId/{id}")
    public ResponseBean listByStationId(@PathVariable String id) {
        return responseSuccessWithData(pointService.listByStationId(id));
    }

    /**
     * 根据参数点名称模糊查询参数点列表
     *
     * @param name
     * @return
     */
    @GetMapping("/listByPointName/{name}")
    public ResponseBean listByPointName(@PathVariable String name) {
        return responseSuccessWithData(pointService.listByPointName(name));
    }

    /**
     * 添加参数点
     *
     * @param point
     * @return
     */
    @PostMapping
    public ResponseBean add(@RequestBody Point point) {
        Map<String, Object> result = new HashMap<>();
        result.put("row", pointService.add(point));
        return responseSuccessWithData(result);
    }

    /**
     * 移除参数点
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseBean remove(@PathVariable String id) {
        Map<String, Object> result = new HashMap<>();
        result.put("row", pointService.remove(id));
        return responseSuccessWithData(result);
    }

    /**
     * 修改参数点
     *
     * @param point
     * @return
     */
    @PutMapping
    public ResponseBean update(@RequestBody Point point) {
        Map<String, Object> result = new HashMap<>();
        result.put("row", pointService.update(point));
        return responseSuccessWithData(result);
    }

}
